import request from './request.js'

// ==================== 订单管理 ====================

// 通过用户名创建订单
export function createOrderByUsername(orderData) {
  return request({
    url: '/Orders/create-by-username',
    method: 'post',
    data: orderData
  })
}

// 根据ID获取订单
export function getOrderById(id) {
  return request({
    url: `/Orders/${id}`,
    method: 'get'
  })
}

// 更新订单
export function updateOrder(id, data) {
  return request({
    url: `/Orders/${id}`,
    method: 'put',
    data
  })
}

// 取消订单
export function cancelOrder(id) {
  return request({
    url: `/Orders/${id}/cancel`,
    method: 'delete'
  })
}

// 获取用户的订单
export function getOrdersByUserId(userId) {
  return request({
    url: `/Orders/user/${userId}`,
    method: 'get'
  })
}

// 根据状态查询用户订单
export function getOrdersByStatus(userId, status) {
  return request({
    url: `/Orders/user/${userId}/status/${status}`,
    method: 'get'
  })
}

// ==================== 购物车相关订单功能 ====================

// 从购物车创建订单
export function createOrderFromCart(userId) {
  return request({
    url: '/Orders/create-from-cart',
    method: 'post',
    params: { userId }
  })
}

// 模拟支付
export function simulatePayment(orderId) {
  return request({
    url: `/Orders/${orderId}/pay`,
    method: 'put'
  })
}

// ==================== 卖家订单管理 ====================

// 获取卖家的订单
export function getSellerOrders(params = {}) {
  return request({
    url: '/Orders/seller',
    method: 'get',
    params
  })
}

// 更新订单状态
export function updateOrderStatus(orderId, status) {
  return request({
    url: `/Orders/${orderId}/status`,
    method: 'put',
    params: { status }
  })
}

// 发货
export function shipOrder(orderId, trackingNumber) {
  return request({
    url: `/Orders/${orderId}/ship`,
    method: 'put',
    params: { trackingNumber }
  })
}

// 确认收货
export function confirmOrder(orderId) {
  return request({
    url: `/Orders/${orderId}/confirm`,
    method: 'put'
  })
}

// ==================== 订单统计 ====================

// 获取订单统计
export function getOrderStats() {
  return request({
    url: '/Orders/stats',
    method: 'get'
  })
}

// 获取用户订单统计
export function getUserOrderStats(userId) {
  return request({
    url: `/Orders/stats/user/${userId}`,
    method: 'get'
  })
}

// 获取卖家订单统计
export function getSellerOrderStats(sellerId) {
  return request({
    url: `/Orders/stats/seller/${sellerId}`,
    method: 'get'
  })
}

// ==================== 买家订单管理 ====================

// 买家订单
export function getOrdersByBuyerId(buyerId) {
  return request({
    url: `/Orders/buyer/${buyerId}`,
    method: 'get'
  })
}

// 买家订单（按状态）
export function getOrdersByStatusB(buyerId, status) {
  return request({
    url: `/Orders/buyer/${buyerId}/status/${status}`,
    method: 'get'
  })
}

// ==================== 卖家订单管理 ====================

// 卖家订单
export function getOrdersBySellerId(sellerId) {
  return request({
    url: `/Orders/seller/${sellerId}`,
    method: 'get'
  })
}

// 卖家订单（按状态）
export function getOrdersByStatusS(sellerId, status) {
  return request({
    url: `/Orders/seller/${sellerId}/status/${status}`,
    method: 'get'
  })
}

// ==================== 支付功能 ====================

// 支付订单
export function payOrder(orderId) {
  return request({
    url: `/Orders/${orderId}/pay`,
    method: 'put'
  })
} 